// Copyright (C) 2015 the V8 project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
es6id: 13.6.4.13
description: >
    If an iterator's `return` method returns a non-Object value, a TypeError
    should be thrown.
features: [Symbol.iterator]
---*/

function Test() {
    var iterable = {};
    var iterationCount = 0;

    iterable[Symbol.iterator] = function() {
      return {
        next: function() {
          return { done: false, value: null };
        },
        return: function() {
          return 0;
        }
      };
    };

    assert.throws(TypeError, function() {
      for (var x of iterable) {
        iterationCount += 1;
        break;
      }
    });

    assert.sameValue(iterationCount, 1, 'The loop body is evaluated');
}

// preheat
const NUMBER_OF_PREHEAT = 1;
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}

ArkTools.jitCompileAsync(Test);
assert.sameValue(ArkTools.waitJitCompileFinish(Test), true, '[JIT] JIT disabled.');

// test
const NUMBER_OF_TEST = 1; // or 2
for (let i = 0; i < NUMBER_OF_PREHEAT; i++) {
    Test();
}
